package com.jzxiang.pickerview;

import android.content.Context;
import android.view.View;

import com.jzxiang.pickerview.adapters.NumericWheelAdapter;
import com.jzxiang.pickerview.config.NumberConfig;
import com.jzxiang.pickerview.data.source.NumRepository;
import com.jzxiang.pickerview.utils.PickerContants;
import com.jzxiang.pickerview.utils.Utils;
import com.jzxiang.pickerview.wheel.OnWheelChangedListener;
import com.jzxiang.pickerview.wheel.WheelView;

/**
 * Created by jzxiang on 16/4/20.
 */
public class NumberWheel {
    Context mContext;

    WheelView number;
    NumericWheelAdapter mNumberAdapter;

    NumberConfig mNumberConfig;
    NumRepository mRepository;
    OnWheelChangedListener numberListener = new OnWheelChangedListener() {
        @Override
        public void onChanged(WheelView wheel, int oldValue, int newValue) {
//            updateMonths();
        }
    };

    public NumberWheel(View view, NumberConfig numberConfig) {
        mNumberConfig = numberConfig;
        mRepository = new NumRepository(mNumberConfig);
        mContext = view.getContext();
        initialize(view);
    }

    public void initialize(View view) {
        initView(view);
        initYear();
    }


    void initView(View view) {
        number = (WheelView) view.findViewById(R.id.number);
        Utils.showViews(number);
        number.addChangingListener(numberListener);
    }

    void initYear() {
        int minValue = mRepository.getMinValue();
        int maxValue = mRepository.getMinValue();

        mNumberAdapter = new NumericWheelAdapter(mContext, minValue, maxValue, PickerContants.FORMAT, mNumberConfig.mUnit);
        mNumberAdapter.setConfig(mNumberConfig);
        number.setViewAdapter(mNumberAdapter);
        number.setCurrentItem(mRepository.getDefaultValue() - minValue);
    }



    public int getCurrentValue() {
        return number.getCurrentItem() + mRepository.getMinValue();
    }




}
